﻿using Sirenix.OdinInspector;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TMPro;
using TowerDefence_Zombie.Data;
using UnityEngine;
using UnityEngine.UI;

namespace TowerDefence_Zombie
{
    public class UIOfflineEarningsForm : UGuiFormEx
    {

        [Title("收益"), SerializeField] private TextMeshProUGUI earningsText;
        [Title("确认按钮"), SerializeField] private Button confirmBtn;
        [Title("关闭按钮"), SerializeField] private Button closeBtn;
        protected override void OnOpen(object userData)
        {
            base.OnOpen(userData);
            earningsText.text = $"x{GameEntry.Data.GetData<DataPlayer>().OfflineEarning}";
            confirmBtn.onClick.AddListener(ConfirmBtn);
            closeBtn.onClick.AddListener(CloseForm);
        }


        private void ConfirmBtn()
        {
            GameEntry.Data.GetData<DataPlayer>().AddCurrency(101, GameEntry.Data.GetData<DataPlayer>().OfflineEarning, CurrencyEvent.OfflineEarnings);
            GameEntry.Data.GetData<DataPlayer>().OfflineEarning = 0;
            CloseForm();
        }

        protected override void OnClose(bool isShutdown, object userData)
        {
            base.OnClose(isShutdown, userData);
            confirmBtn.onClick.RemoveListener(ConfirmBtn);
            closeBtn.onClick.RemoveListener(CloseForm);
        }


        private void CloseForm()
        {
            base.Close();
        }
    }
}
